// 登录接口
import {request} from '../utils/request'

const questionApi = {
  findAllKnowledgePoints: '/subject/findAllKnowledgePoints',
  findAllSubjects: '/subject/findAllSubjects',
  getKnowledgePoints: '/subject/getKnowledgePoints',
  getQuestionByKnowledgePoint: '/question/search',
  findSubjectByID: '/subject/findSubjectByID',
  findQuestions: '/question/search',
  findQuestionsinBank: '/questionBank/search',
  findBankById: '/questionBank/liberary/search',
  addToBank: 'questionBank/addQuestion',
  findSubjectByName: '/subject/findSubjectByName'
}

// 查找所有知识点
export function findAllKnowledgePoints (parameter) {
  return request({
    url: questionApi.findAllKnowledgePoints,
    method: 'get',
    params: parameter
  })
}
// 查询所有科目
export function findAllSubjects (parameter) {
  return request({
    url: questionApi.findAllSubjects,
    method: 'get',
    params: parameter
  })
}

// 查询某科目的所有知识点
export function getKnowledgePoints (id) {
  return request({
    url: questionApi.getKnowledgePoints,
    method: 'get',
    params: {
      subjectId: id
    }
  })
}

// 根据知识点查询题目
export function getQuestionByKpointandType (bid, kid, type) {
  return request({
    url: questionApi.findQuestionsinBank,
    method: 'get',
    params: {
      index: 0,
      page_size: 10,
      questionBankId: bid,
      knowledgePointId: kid,
      questionType: type
    }
  })
}

// 根据id查找科目
export function findSubjectByID (id) {
  return request({
    url: questionApi.findSubjectByID,
    method: 'get',
    params: {
      id: id
    }
  })
}

// 根据关键字查找题目
export function findQuestions (index, pageSize, param) {
  return request({
    url: questionApi.findQuestions,
    method: 'get',
    params: {
      index: index,
      page_size: pageSize,
      questionStem: param
    }
  })
}

// 根据关键字查询某个老师的某个题库中的题目
export function findQuestionsofBank (index, pageSize, question, bankId) {
  return request({
    url: questionApi.findQuestions,
    method: 'get',
    params: {
      index: index,
      page_size: pageSize,
      questionStem: question,
      bankId: bankId
    }
  })
}

// 根据题库id查找题库信息
export function findBankById (index, pageSize, bankId) {
  return request({
    url: questionApi.findBankById,
    method: 'get',
    params: {
      index: index,
      page_size: pageSize,
      id: bankId
    }
  })
}

// 把题目加入题库
export function addToBank (bid, qid) {
  return request({
    url: questionApi.addToBank,
    method: 'post',
    params: {
      bankId: bid,
      questionId: qid
    }
  })
}

// 查询某题库中的题目
export function findQuestionFromBank (bid) {
  return request({
    url: questionApi.findQuestionsinBank,
    method: 'get',
    params: {
      questionBankId: bid
    }
  })
}

// 根据名称查询科目
export function findSubjectByName (sname) {
  return request({
    url: questionApi.findSubjectByName,
    method: 'get',
    params: {
      name: sname
    }
  })
}
